package com.jiang.daily.Q3195;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/08/22 10:31
 */
class Solution {
    public int minimumArea(int[][] grid) {
        int u = Integer.MAX_VALUE, l = Integer.MAX_VALUE;
        int d = Integer.MIN_VALUE, r = Integer.MIN_VALUE;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[0].length; j++) {
                if (grid[i][j] == 1) {
                    u = Math.min(u, i);
                    l = Math.min(l, j);
                    d = Math.max(d, i);
                    r = Math.max(r, j);
                }
            }
        }
        return (d - u + 1) * (r - l + 1);
    }
}
